package cn.getech.data.metadata.db.data;

import cn.getech.data.metadata.constant.ConnectTypeEnum;
import cn.getech.data.metadata.db.DataView;
import cn.getech.data.metadata.entity.meta.CollectionTableInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service("dataViewOracleImpl")
public class DataViewOracleImpl implements DataView {

    @Override
    public boolean support(Integer type) {
        return ConnectTypeEnum.Oracle.getCode().equals(type);
    }

    @Override
    public String getSql(CollectionTableInfo table, List<String> fieldList, Integer page, Integer limit) {
        String sql = "select " + String.join(",", fieldList) + "  from  %s.%s  where  rownum <= %d";
        sql = String.format(sql, table.getDbName(), table.getTableName(),limit);
        return sql;
    }

    @Override
    public String getCountSql(CollectionTableInfo table) {
        String sql = "select  count(*) as totalCount  from  %s.%s  ";
        return String.format(sql, table.getDbName(), table.getTableName());
    }
}
